FROM maodouzi/django:v2.2.6-oracleclient-v19.3

ENV project_name=mysite
ENV project_app_name=mysite

# remote_workdir=/home/www/mysite
ENV remote_workdir=/home/www/$project_name

# Build folder
RUN mkdir -p $remote_workdir/logs \
    && mkdir -p $remote_workdir/tool \
    && mkdir -p $remote_workdir/src

# remote_app_dir=/home/www/mysite/src/mysite   
ENV remote_app_dir=$remote_workdir/src/$project_app_name

# remote_workdir=/home/www/mysite/src   
WORKDIR $remote_workdir

# /home/www/django-account/src 
COPY . ./src

RUN rm -rf $remote_app_dir/data \
    && pip install -r $remote_workdir/src/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \
    && cd $remote_app_dir \
    && rm -rf static \
    && python manage.py collectstatic

# Setup nginx
RUN rm -rf /etc/nginx/sites-enabled/default
ADD docker-config/nginx.conf /etc/nginx/sites-available/$project_name.conf
RUN ln -s /etc/nginx/sites-available/$project_name.conf /etc/nginx/sites-enabled/$project_name.conf
# RUN echo "daemon off;" >> /etc/nginx/nginx.conf

ADD docker-config/supervisord.conf /etc/supervisor/supervisord.conf
ADD docker-config/supervisor.conf /etc/supervisor/conf.d/$project_name.conf
ADD docker-config/start.sh /tmp/start.sh
EXPOSE 80
CMD [ "sh", "/tmp/start.sh" ]
